package lumis.portal.webfilereplication;

import lumis.portal.filesystem.PortalFile;

/**
 * Helper for WebFileReplication that handles the path filter conditions.
 * Provides the matches method that decides whether the given PortalFile must
 * be processed or not given a value to path filter.
 * The PortalFile must be processed when its relative path matches with the
 * expression chosen in path filter. 
 * Also, when the filter is null or empty, any PortalFile must be processed.
 * 
 * @version $Revision: 13093 $ $Date: 2011-05-28 18:40:18 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
class FilterPathHelper
{
	/**
	 * Returns true if the PortalFile path matches the filterPath regexp.
	 * @param file			an instance of PortalFile.
	 * @param filterPath	a regular expression.
	 * @return	true if the PortalFile path matches the filterPath otherwise returns false.
	 * @since 6.0.0
	 */
	static boolean matches(PortalFile file, String filterPath)
	{
		if ((filterPath == null) || (filterPath.equals("")))
		{
			return true;
		}
		
		String portalFilePath = "/" + file.getPortalFilePath().getRelativePath();
		return portalFilePath.matches(filterPath);
		
	}
}